<!DOCTYPE html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Digital</title>
    <script>
        function displayTime() {
            var elt = document.getElementsByClassName("clock");     // 通过id = "clock"找到元素
            var now = new Date();                                   // 得到当前时间
            elt.innerHTML = now.toLocaleTimeString();               // 让elt来显示它
            setTimeout(displayTime, 1000);                           // 在一秒后再次执行
        }

        window.onload = displayTime;                                // 当onload事件发生时开始显示时间


    </script>
    <style>
        #clock {
            font: bold 24pt sans;
            background: #ddf;
            padding: 10px;
            border: solid black 2px;
            border-radius: 10px;
        }
    </style>

</head>



<body>
    <h1>Digital Clock</h1>
    <span id="clock" >点我</span>
</body>

</html>